﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Koonsoft.HYCRM.BLL;
using Koonsoft.HYCRM.Model;

public partial class Auditors_EnterBank2 : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string str1 = "<script>var x = [";

            foreach (int v in Enum.GetValues(typeof(ExplainEnum)))
            {
                ExplainEnum pStatus = (ExplainEnum)v;
                dropExplain.Items.Add(new ListItem(RemarkAttribute.GetEnumRemark(pStatus), v.ToString()));
                str1 += "'" + RemarkAttribute.GetEnumRemark(pStatus) + "',";
            }
            str1 = str1.TrimEnd(',') + "]</script>";
            Label1.Text = str1;

            if (Request["type"].ToString() == "Check")
            {
                dropCurrency.Items.Add(new ListItem("支票账户", "99"));
            }
            else if (Request["type"].ToString() == "Savings")
            {
                dropCurrency.Items.Add(new ListItem("储蓄账户", "98"));
            }
            else if (Request["type"].ToString() == "US")
            {
                dropCurrency.Items.Add(new ListItem("美金", "2"));
            }
            else if (Request["type"].ToString() == "RMB")
            {
                dropCurrency.Items.Add(new ListItem("人民币", "3"));
            }
            else if (Request["type"].ToString() == "GBP")
            {
                dropCurrency.Items.Add(new ListItem("英镑", "4"));
            }
            else if (Request["type"].ToString() == "CAD")
            {
                dropCurrency.Items.Add(new ListItem("加拿大元", "5"));
            }
            else if (Request["type"].ToString() == "CHF")
            {
                dropCurrency.Items.Add(new ListItem("瑞士法郎", "7"));
            }
            else if (Request["type"].ToString() == "JPY")
            {
                dropCurrency.Items.Add(new ListItem("日元", "8"));
            }
            else if (Request["type"].ToString() == "AUD")
            {
                dropCurrency.Items.Add(new ListItem("澳元", "9"));
            }
            else if (Request["type"].ToString() == "EUR")
            {
                dropCurrency.Items.Add(new ListItem("欧罗", "10"));
            }
            //else
            //{
            //    foreach (int v in Enum.GetValues(typeof(CurrencyEnum)))
            //    {
            //        if (v != 1 && v!=2)
            //        {
            //           CurrencyEnum pStatus = (CurrencyEnum)v;
            //            dropCurrency.Items.Add(new ListItem(RemarkAttribute.GetEnumRemark(pStatus), v.ToString()));

            //        }
            //    }
            //}

            GetMantissa(dropCurrency.SelectedValue);
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        HttpCookie cookie = Request.Cookies["Bank"];

        if (cookie != null)
        {
            List<CreateBankEntity> list = new List<CreateBankEntity>();
            string company = Request.QueryString["CompanyID"];
            string orderid = Request.QueryString["orderid"];
            foreach (string s in System.Web.HttpUtility.UrlDecode(cookie.Value).TrimEnd(';').Split(';'))
            {
                list.Add(new CreateBankEntity()
                {
                    VoucherNo = s.Split('~')[0],
                    Date = s.Split('~')[1],
                    Explain = s.Split('~')[3],
                    Amount = s.Split('~')[2],
                    Currency = dropCurrency.SelectedValue,
                    OrderID = orderid,
                    CompanyID = company
                });

            }
            string msg;

            if (new AuditorsBLL().CreateCompanyBank(list, out msg))
            {
                Response.Redirect("SelectBank.aspx?CompanyID=" + company + "&orderid=" + orderid);
            }
            else
            {
                if (msg.ToLower().StartsWith("sql自定义异常:"))
                {
                    AlertMsg(msg.ToLower().Replace("sql自定义异常:", ""));
                }
                else
                {
                    AlertMsg("插入失败，请检查数据是否异常");
                }
            }
        }
    }
    protected void dropCurrency_SelectedIndexChanged(object sender, EventArgs e)
    {
        GetMantissa(dropCurrency.SelectedValue);
    }

    private void GetMantissa(string currency)
    {
        string company = Request.QueryString["CompanyID"];
        string orderid = Request.QueryString["orderid"];

        Text1.Text = new AuditorsBLL().GetLastCompanyBankMantissa(company, orderid, currency).ToString();
    }
}